package com.itheima.mapper;

import com.itheima.domain.Account;
import com.itheima.domain.Trip;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AccountMapper {
    /*
     编程题目二
  */
    //1、查询行程表中所有的数据
    @Select("SELECT id, username, gender, idcard, from_address, to_address, start_time FROM tb_trip;")
    List<Account> findAll();

    //2、添加用户过年的行程数据
    @Insert("INSERT INTO tb_trip VALUE (NULL, #{username}, #{gender}, #{idCard}, #{from_address}, #{to_address}, #{start_time});")
    void save(Account account);

    //3、根据ID删除用户的行程数据
    @Delete("DELETE FROM tb_trip WHERE id = #{id}")
    void delete(Integer id);

    //4、根据ID修改用户的行程数据
    @Update("UPDATE tb_trip SET username = #{username}, gender = #{gender}, idcard = #{idCard}, from_address = #{from_address}, to_address = #{to_address}, start_time = #{start_time} WHERE id = #{id};")
    void update(Account account);

    //5、根据ID查询用户的行程数据
    @Select("SELECT id, username, gender, idcard, from_address, to_address, start_time FROM tb_trip WHERE id = #{id};")
    Account findById(Integer id);

    /*
     编程题目三
  */
    //1. 查询旧表中所需数据
    @Select("SELECT id, from_address, to_address, start_time FROM tb_trip;")
    List<Trip> QueryAll();

    //2. 向新表插入所需数据 --使用动态SQL
    void insertDataToNewTable(List<Trip> trips);

    //3. 关联查询所有数据
    List<User> newQueryAll();

}